package cn.sdack.go.common.entities.users;

import cn.sdack.go.common.entities.PermissionEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.*;

/**
 * @author sdack
 * @date 2023/12/26
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "users", indexes = {
        @Index(name = "idx_users_account",columnList = "account",unique = true)
})
public class UserEntity extends PermissionEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    // 授权服务器账号
    @Builder.Default
    @Column(length = 50, nullable = false)
    private String account = "0";

    // 上级用户
    @JsonIgnore
    @Builder.Default
    private Long pid = 0L;

    // 身份
    @Column(length = 30, nullable = false)
    private String identity;

    @Column(length = 180, nullable = false)
    private String nickname;

    @Column(length = 180, nullable = false)
    private String username;

    @Column(length = 150, nullable = false)
    private String email;

    @Column(length = 30, nullable = false)
    private String phone;

    @Column(length = 500)
    private String avatar;

    // 用户可用状态
    @Builder.Default
    @Column( nullable = false)
    private Boolean stats = true;

    public enum Identity {
        SUPER("super", "超级管理员"),
        ADMIN("admin", "管理员"),
        GROUP_ADMIN("group_admin", "组织管理员"),
        GROUP("group", "组织人员"),
        SIMPLE("simple", "普通人员"),
        ;

        public String code;
        public String name;
        Identity(String code,String name) {
            this.code = code;
            this.name = name;
        }
    }

}
